local jass = require 'jass.common'
local japi = require 'jass.japi'
local dbg = require 'jass.debug'

local mt = {}

mt.type_list = {
    ['+loc'] = 'location',
    ['+EIP'] = 'effect',
    ['+EIm'] = 'effect',
    ['+EIf'] = 'effect',
    ['+tmr'] = 'timer',
    ['+w3d'] = 'destructable',
    ['item'] = 'item',
    ['+w3u'] = 'unit',
    ['+ply'] = 'player',
    ['+rct'] = 'rect',
    ['+agr'] = 'region',
    ['+snd'] = 'sound',
    ['+trg'] = 'trigger',
}

-- [获取handle类型]
function mt.get_type(handle)
    if not handle or handle == 0 then 
        return nil 
    end 
    local handledef = dbg.handledef(handle)
    if handledef and handledef.type then 
        return mt.type_list[handledef.type]
    end 
end 

local GetUnitTypeId = jass.GetUnitTypeId
local GetItemTypeId = jass.GetItemTypeId
local GetDestructableTypeId = jass.GetDestructableTypeId

-- [是一个单位handle]
function mt.is_unit(handle)
    if not handle or handle == 0 then 
        return false 
    end 
    return GetUnitTypeId(handle) ~= 0
end 

-- [是一个物品handle]
function mt.is_item(handle)
    if not handle or handle == 0 then 
        return false 
    end 
    return GetItemTypeId(handle) ~= 0
end 

-- [是一个可破坏物handle]
function mt.is_destructable(handle)
    if not handle or handle == 0 then 
        return false 
    end 
    return GetDestructableTypeId(handle) ~= 0
end 

return mt


